import { IFeidaoAiMobile } from '@dfeidao/atom-mobile/interfaces';
import get from '@dfeidao/atom-mobile/local/get';
import nodejs from '@dfeidao/atom-mobile/msg/nodejs';
import show_sheet from '@dfeidao/atom-mobile/msgbox/action-sheet';
import toast from '@dfeidao/atom-mobile/msgbox/toast';
import render from '@dfeidao/atom-mobile/render/render';

export default async function a005(fd: IFeidaoAiMobile) {
	// 班级
	const grade_name = get(fd, 'grade_name');
	const grade_no = get(fd, 'grade_no');
	const productid = get(fd, 'productid');
	if (grade_name && grade_no) {
		const options = new Array();
		const res = await nodejs<{ data: Array<{ class_name: string; class_id: string; }> }>('app-my-schedule/s004', { productid, grade_no });
		for (let i = 0; i < res.data.length; i++) {
			const text = res.data[i].class_name;
			options.push(text);
		}
		options.push('取消');
		const ind = await show_sheet({
			options,
			title: '选择班级'
		});
		const clas_n = res.data[ind];
		if (clas_n) {
			const class_name = clas_n.class_name;
			const class_id = clas_n.class_id;
			const res1 = await nodejs<{ dest: Array<{}> }>('app-my-schedule/s005', { productid, grade_no, class_id });
			render(fd, { class_name, data: res1.dest });
		}
	} else {
		toast({
			type: 'warning',
			text: '请先选择年级',
			position: 'top'
		});
	}

}
